import java.util.*;
import java.util.Map.*;

public class 遍历 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            list.add("aaa:" + i);
        }

        // 第一种遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        System.out.println("###################");

        //第二种遍历
        for (String s : list) {
            System.out.println(s);
        }

        System.out.println("###################");

        //第三种遍历
        for (Iterator<String> ss = list.iterator(); ss.hasNext(); ) {
            String temp = ss.next();
            System.out.println(temp);
        }

        System.out.println("###################");

        //第四种遍历
        Iterator<String> ss = list.iterator();
        while (ss.hasNext()) {
            String temp = ss.next();
            System.out.println(temp);
        }

//        Set<String> set = new HashSet<>();
        Set<String> set = new TreeSet<>();
        for (int i = 0; i < 5; i++) {
            set.add("bbb:" + i);
        }

        System.out.println("###################");

        //第一种遍历
        for (String s : set) {
            System.out.println(s);
        }

        System.out.println("###################");

        //第二种遍历
        for (Iterator<String> sss = set.iterator(); sss.hasNext(); ) {
            String temp = sss.next();
            System.out.println(temp);
        }

        System.out.println("###################");

        //第三种遍历
        Iterator<String> sss = set.iterator();
        while (sss.hasNext()) {
            String temp = sss.next();
            System.out.println(temp);
        }

        Map<Integer, String> map = new HashMap<>();
        for (int i = 0; i < 5; i++) {
            map.put(i, "ccc:" + i);
        }
        System.out.println(map);

        //第一种遍历
        Set<Integer> sSet = map.keySet();
        for (Integer id : sSet) {
            System.out.println(id + "---->" + map.get(id));
        }

        System.out.println("###################");

        //第二种遍历
        Set<Integer> sSet1 = map.keySet();
        for(Iterator<Integer> iter = sSet1.iterator();iter.hasNext();){
            int id = iter.next();
            System.out.println(id + "---->" + map.get(id));
        }

        System.out.println("###################");

        //第三种遍历
        Set<Entry<Integer, String>> sMap = map.entrySet();
        for(Iterator<Entry<Integer, String>> iter = sMap.iterator();iter.hasNext();){
            Entry e = iter.next();
            System.out.println(e.getKey() + "---->" + e.getValue());
        }

        System.out.println("###################");

        //第四种遍历
        Set<Entry<Integer, String>> sMap1 = map.entrySet();
        for (Entry<Integer, String> e : sMap1) {
            System.out.println(e.getKey() + "---->" + e.getValue());
        }
    }
}
